package cn.ryh.hystrix.consumer.controller;

import cn.hutool.core.util.IdUtil;
import cn.ryh.hystrix.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName PaymentController
 * @Description TODO
 * @Author RaoYH
 * @CreateDate 2020/11/20
 * @UpdateUser RaoYH
 * @UpdateDate 2020/11/20
 * @UpdateRemark TODO
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/consumer")
@DefaultProperties(defaultFallback = "defaultFallback")
public class ConsumerController {
    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping(value = "/getServer")
    public String getServer() {
        return paymentFeignService.getServer();
    }

    @GetMapping(value = "/getServerTimeOut")
    @HystrixCommand(fallbackMethod = "getServerTimeOutFallback",commandProperties = {
            //3秒钟以正常，超过3秒走兜底方法。
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "4000")
    })
    public String getServerTimeOut() {
        return paymentFeignService.getServerTimeOut();
    }

    public String getServerTimeOutFallback() {
        return "Spring cloud with hystrix order getServerTimeOutFallback";
    }
    public String defaultFallback() {
        return "defaultFallback";
    }
}
